/*
 * @Description: 数据字典 - 接口
 * @Author: DSY
 * @Date: 2022-03-19 22:53:48
 * @LastEditors: DHL
 * @LastEditTime: 2022-04-13 09:58:03
 */

import { $get, $post, $put } from '@/utils/http'
import { ContentTypeEnum } from '@/constant/http'
import {
  DataDicListResultModel,
  DataDicModel,
  DataDicPageParams,
  DataDicPageResultModel,
  DataDicParams,
  DataDicResultModel
} from './model/dataDicModel'
import { Result } from '@/model/baseModel'

/**
 * 分页查询
 */
export const apiDataDicSearch = (searchParams: DataDicPageParams) =>
  $get<DataDicPageResultModel>({
    url: '/system/twbDataDic/search',
    params: searchParams
  })

/**
 * 根据ID获取详情
 */
export const apiDataDicGetById = (id: string) =>
  $get<DataDicResultModel>({
    url: '/system/twbDataDic/getById',
    params: { id: id }
  })

/**
 * 保存信息
 */
export const apiDataDicSave = (saveParams: DataDicModel) =>
  $post<DataDicResultModel>({
    url: '/system/twbDataDic/save',
    contentType: ContentTypeEnum.json,
    params: saveParams
  })

/**
 * 更新信息
 */
export const apiDataDicUpdateById = (updateParams: DataDicModel) =>
  $put<DataDicResultModel>({
    url: '/system/twbDataDic/updateById',
    contentType: ContentTypeEnum.json,
    params: updateParams
  })

/**
 * 根据ID删除信息
 */
export const apiDataDicDeleteById = (id: string) =>
  $post<DataDicResultModel>({
    url: '/system/twbDataDic/deleteById',
    params: { id: id }
  })

/**
 * 批量删除信息
 */
export const apiDataDicBatchDeleteByIds = (ids: string) =>
  $post<DataDicResultModel>({
    url: '/system/twbDataDic/batchDeleteByIds',
    params: { ids: ids }
  })

/**
 * 获取下一个顺序号
 * @param typeCode
 * @param isParent 是否使用父级ID查询(1-是，2-否)
 * @returns
 */
export const apiDataDicGetNextSeqNumByTypeCode = (typeCode: string, isParent: string) =>
  $get<Result<number>>({
    url: '/system/twbDataDic/getNextSeqNumByTypeCode',
    params: { typeCode: typeCode, isParent: isParent }
  })

/**
 * 获取下一个类别顺序号
 * @param typeCode
 * @returns
 */
export const apiDataDicGetNextTypeSeqByTypeCode = (typeCode: string) =>
  $get<Result<number>>({
    url: '/system/twbDataDic/getNextTypeSeqByTypeCode',
    params: { typeCode: typeCode }
  })

/**
 * 字典树查询
 * @param searchParams
 */
export const apiDataDicSearchTree = (searchParams: DataDicParams) =>
  $get<DataDicListResultModel>({
    url: '/system/twbDataDic/searchTree',
    params: searchParams
  })

/**
 * 数据字典类别查询
 * @param searchParams
 */
export const apiDataDicListDataType = (searchParams: any) =>
  $get<DataDicListResultModel>({
    url: '/system/twbDataDic/listDataType',
    params: searchParams
  })

/**
 * 根据类别编码查询一个对象
 */
export const apiDataDicGetDataDicByTypeCode = (typeCode: string) =>
  $get<DataDicResultModel>({
    url: '/system/twbDataDic/getDataDicByTypeCode',
    params: { typeCode: typeCode }
  })

/**
 * 更新类别层级信息
 * @param typeCode
 * @param parentId
 */
export const apiDataDicUpdateParentIdByTypeCode = (updateParams: any) =>
  $post<Result<string>>({
    url: '/system/twbDataDic/updateParentIdByTypeCode',
    contentType: ContentTypeEnum.json,
    params: updateParams
  })
